package com.rk.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rk.admin.domain.Briefinfo;
import com.rk.admin.domain.Comarticle;
import com.rk.admin.domain.Particle;
import com.rk.admin.mapper.BriefInfoMapper;
import com.rk.admin.service.BriefinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BriefinfoServiceImpl implements BriefinfoService {
    @Autowired
    private BriefInfoMapper briefInfoMapper;

    @Override
    public Briefinfo selectHomepage() {
        return briefInfoMapper.queryBymodel(5);
    }

    /**
     * 通过id修改中心简介
     *
     * @param briefinfo
     * @return
     */
    @Override
    public Boolean updatebyid(Briefinfo briefinfo) {
        return briefInfoMapper.updatebyid(briefinfo)>0;
    }

    /**
     * 分页查询中心简介
     *
     * @param page
     * @param limit
     * @param title
     * @return
     */
    @Override
    public IPage<Briefinfo> selectPage(int page, int limit, String title) {
        IPage<Briefinfo> briefinfoIPage=new Page<>(page,limit);
        LambdaQueryWrapper<Briefinfo> lqw=new LambdaQueryWrapper<Briefinfo>();
        //根据id降序
        lqw.orderByDesc(Briefinfo::getId);

        //查询指定字段
        //lqw.select(Briefinfo::getId,Briefinfo::getTitle,Briefinfo::getCreatime,Briefinfo::getModel);

        //lqw.eq(Briefinfo::getTags,1);

        //根据文章标题进行条件查询
        if(!"".equals(title)&&title!=null){
            lqw.like(Briefinfo::getTitle,title);
        }

        briefInfoMapper.selectPage(briefinfoIPage,lqw);
        return briefinfoIPage;
    }

}
